import { createRouter, createWebHistory } from "vue-router";
import Login from "../components/Login.vue";
import Regist from "../components/Regist.vue";
import ShowScedule from "../components/ShowSchedule.vue";

//pinia在路由配置
import pinia from "../pinia.js";
import { createuser } from "../store/userStore.js";
let user = createuser(pinia);

let router = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: "/",
      redirect: "/showSchedule",
    },
    {
      path: "/login",
      component: Login,
    },
    {
      path: "/showSchedule",
      component: ShowScedule,
    },
    {
      path: "/regist",
      component: Regist,
    },
  ],
});
router.beforeEach((to, from, next) => {
  if (to.path == "/showSchedule") {
    if (user.username == "") {
      next("/login");
    } else {
      next();
    }
  } else {
    next();
  }
});
export default router;
